<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>

  <TITLE>CS631 -- Advanced Programming in the UNIX Environment</TITLE>
  <STYLE type="text/css">
  body {
  background-color: #FFFFFf;
  }
  </STYLE>
</HEAD>

<BODY>
  <TABLE border="1" align="center" cellpadding="15">
    <TR>
      <TD valign="top">
        <H2>CS631 -- Advanced Programming in the UNIX Environment - Exercise</H2>

        <H3>Implement the 'libgreet' library.</H3>

<h4>Summary</h4>

<p>In this assignment you will write a simplistic shared library.  The
functionality it provides is defined in the <a
href="greet.3.txt">greet(3)</a> manual page. In order to minimize any
errors, it is important that you follow the instructions provided to you
in this document closely.</p>

<ul>
<li><p>Begin by creating a directory named after your Stevens username:</p>
<P><blockquote><pre><tt>$ mkdir ${USER}-hw4</tt></pre></blockquote></p></li>

<li><p>Change into that directory:</p>
<P><blockquote><pre><tt>$ cd ${USER}-hw4</tt></pre></blockquote></p></li>

<li><p>Download the program <a href="hello.c">hello.c</a>:</p>
<P><blockquote><pre><tt>$ wget https://www.cs.stevens.edu/~jschauma/631/hello.c
$ chmod a-w hello.c</tt></pre></blockquote></p>

<P>You will <b>not modify this file at all</b>.  The objective is for you
to write a stand-alone shared library that allows this program to compile
and run correctly.</p></li>

<li><p>Create a directory for your library, named "libgreet":</p>
<P><blockquote><pre><tt>$ mkdir libgreet</tt></pre></blockquote></p></li>

<li><p>In this directory, begin by creating a header file <tt>greet.h</tt>,
which includes the forward declarations of the functions provided in the
library.  With that in place, you can already compile (although not link)
your main program using this exact command:</p>

<P><blockquote><pre><tt>$ cc -Wall -Werrors -c hello.c -I./libgreet</tt></pre></blockquote></p></li>


<li><p>Next, create the file <tt>libgreet/greet.c</tt>, which implements the
functionality of the library.  Then, use the lessons from <a
href="lecture11.pdf">lecture 11</a> to create a shared library
<tt>libgreet/libgreet.so</tt>.  Create a <tt>Makefile</tt> to build this
library, so that the following command will work:</p>

<P><blockquote><pre><tt>$ make lib
$ file libgreet/libgreet.so
libgreet/libgreet.so: symbolic link to 'libgreet.so.1.0'
$ file libgreet/libgreet.so.1.0
libgreet/libgreet.so.1.0: ELF 64-bit LSB shared object, x86-64,
version 1 (SYSV), dynamically linked, for NetBSD 7.0, not stripped</tt></pre></blockquote></p></li>

<li><p>Verify that you can now compile the 'hello.c'
program using this exact command:</p>

<P><blockquote><pre><tt>$ cc -Wall -Werrors -c hello.c -I./libgreet -L./libgreet -lgreet
$ ./a.out
Hello!
Howdy!
you there: Howdy!
</tt></pre></blockquote></p></li>

<li><p>Now create your submission using these exact commands:</p>

<P><blockquote><pre><tt>$ cd ..
$ tar zcf ${USER}-hw4.tar.gz ${USER}-hw4</tt></pre></blockquote></p></li>

<li><p>Attach the resulting <tt>tar.gz</tt> file to an email sent from your
@stevens.edu email address to <a
href="mailto:jschauma@stevens.edu?subject=[CS631]
HW4">jschauma@stevens.edu</a> with a subject of "[CS631] HW4".  The
submission must be sent prior to 2017-11-13 20:45:00 EST.</p></li>
</ul>

        <hr>
        [<a href="index.html">Course Website</a>]
</BODY>
</HTML>
